#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import shutil

## file tools class
class FileTools(object):
    ## check if a file is present
    # @param file_path the full path of file to check
    # @return true if the specified file is present
    @staticmethod
    def is_file_present(file_path):
        return os.path.exists(file_path)
    
    ## read text from file
    # @param file_path full path of file to read
    # @return a str type object 
    @staticmethod
    def read_text(file_path):
        with open(file_path, 'r') as f:
            result = f.read()
        return result
    
    ## read binary from file
    # @param file_path full path of file to read
    # @return the content
    @staticmethod
    def read_binary(file_path):
        with open(file_path, 'rb') as f:
            result = f.read()
        return result
    
    ## save text to file
    # @param text the text to save
    # @param file_path the full path of the output file
    # @return none
    @staticmethod
    def save_text(text, file_path, encoding='UTF-8'):
        with open(file_path, 'w', encoding) as f:
            f.write(text)
            
            
    ## save binary to file
    # @param data data to save
    # @param file_path the full path of the output file
    # @return none
    @staticmethod
    def save_binary(data, file_path):
        with open(file_path, 'wb') as f:
            f.write(data)
    
    ## delete a file
    # @param file_path full path of the file to delete
    # @param raise_except raise no exception if set to false. Default is true
    # @return none
    @staticmethod
    def delete_file(file_path, raise_exception=True):
        if not raise_exception:
            try:
                os.remove(file_path)
            except: # pylint: disable-msg=W0702
                return
        else:
            os.remove(file_path)
        
    @staticmethod
    def copy_folder(input_folder, output_folder):        
        shutil.copytree(input_folder, output_folder)
        
## parse tool class
class ParseTools(object):
    @staticmethod
    def str_to_boolean(val):
        if val:
            return val.lower().strip() in ['1', 'true']
        else:
            return False
    
    